package com.lightningtrade.controller;

import com.lightningtrade.domain.SysReview;
import com.lightningtrade.service.SysReviewService;
import com.lightningtrade.util.AjaxResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 评价管理控制器
 */
@Api(tags = "评价管理-0312杜晟玮")
@RestController
@RequestMapping("/reviews")
public class SysReviewController {

    @Autowired
    private SysReviewService sysReviewService;

    /**
     * 添加评价
     * @param sysReview 评价对象
     * @return AjaxResult
     */

    @ApiOperation(value = "添加评价", notes = "添加新的评价")
    @PostMapping("/add")
    public AjaxResult addReview(@Validated @RequestBody SysReview sysReview) {
        return sysReviewService.addReview(sysReview);
    }

    /**
     * 根据用户ID获取评价列表
     * @param userId 用户ID
     * @return AjaxResult
     */
    @ApiOperation(value = "根据用户ID获取评价列表", notes = "根据用户ID获取评价列表")
    @GetMapping("/user/{userId}")
    public AjaxResult getReviewsByUser(@PathVariable int userId) {
        return sysReviewService.getReviewsByUser(userId);
    }

    /**
     * 根据商品ID获取评价列表
     * @param productId 商品ID
     * @return AjaxResult
     */
    @ApiOperation(value = "根据商品ID获取评价列表", notes = "根据商品ID获取评价列表")
    @GetMapping("/product/{productId}")
    public AjaxResult getReviewsByProduct(@PathVariable int productId) {
        return sysReviewService.getReviewsByProduct(productId);
    }

    /**
     * 根据订单ID获取评价列表
     * @param orderId 订单ID
     * @return AjaxResult
     */
    @ApiOperation(value = "根据订单ID获取评价列表", notes = "根据订单ID获取评价列表")
    @GetMapping("/order/{orderId}")
    public AjaxResult getReviewsByOrder(@PathVariable long orderId) {
        return sysReviewService.getReviewsByOrder(orderId);
    }

    /**
     * 删除评价
     * @param id 评价ID
     * @return AjaxResult
     */
    @ApiOperation(value = "删除评价", notes = "根据评价ID删除评价")
    @DeleteMapping("/delete/{id}")
    public AjaxResult deleteReview(@PathVariable int id) {
        return sysReviewService.deleteReview(id);
    }
}
